home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / FILEDOC.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  132 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Definition of class TFileDocument
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_FILEDOC_H)
  10. #define OWL_FILEDOC_H
  11.  
  12. #if !defined(OWL_DOCVIEW_H)
  13. # include <owl/docview.h>
  14. #endif
  15. #if !defined(__IOSTREAM_H)
  16. # include <iostream.h>
  17. #endif
  18.  
  19. #if defined(BI_NAMESPACE)
  20. namespace OWL {
  21. #endif
  22.  
  23. // Generic definitions/compiler options (eg. alignment) preceeding the 
  24. // definition of classes
  25. #include <services/preclass.h>
  26.  
  27. //
  28. // class TFileDocument
  29. // ~~~~~ ~~~~~~~~~~~~~
  30. class _OWLCLASS TFileDocument : public TDocument {
  31.   public:
  32.     enum TFileDocProp {
  33.       PrevProperty = TDocument::NextProperty-1,
  34.       CreateTime,        // FILETIME
  35.       ModifyTime,        // FILETIME
  36.       AccessTime,        // FILETIME
  37.       StorageSize,       // ulong
  38.       FileHandle,        // platform file handle (HFILE if Windows)
  39.       NextProperty,
  40.     };
  41.  
  42.     TFileDocument(TDocument* parent = 0);
  43.    ~TFileDocument();
  44.  
  45.     // Implement virtual methods of TDocument
  46.     //
  47.     bool        Open(int mode, const char far* path=0);
  48.     bool        Close();
  49.     TInStream*  InStream(int mode, const char far* strmId=0);
  50.     TOutStream* OutStream(int mode, const char far* strmId=0);
  51.     bool        Commit(bool force = false);
  52.     bool        Revert(bool clear = false);
  53.     bool        IsOpen();
  54.  
  55.     int         FindProperty(const char far* name);  // return index
  56.     int         PropertyFlags(int index);
  57.     const char* PropertyName(int index);
  58.     int         PropertyCount();
  59.     int         GetProperty(int index, void far* dest, int textlen=0);
  60.     bool        SetProperty(int index, const void far* src);
  61.  
  62.     // Additional methods for file document
  63.     //
  64.     bool        Open(HFILE fhdl);     // open on existing file handle
  65.  
  66.   protected:
  67.     HFILE OpenThisFile(int omode, const char far* name, streampos* pseekpos);
  68.     void  CloseThisFile(HFILE fhdl, int omode);
  69.  
  70.   protected_data:
  71.     HFILE    FHdl;         // file handle if held open at the document level
  72.  
  73.   private:                 // cached info for property access
  74.     bool     InfoPresent;
  75.     ulong    FileLength;
  76.  
  77. #if defined(BI_PLAT_WIN32)
  78.     FILETIME FileCreateTime;
  79.     FILETIME FileAccessTime;
  80.     FILETIME FileUpdateTime;
  81. #else
  82.     ulong    CalcFileLength(HFILE file);
  83.     ulong    FileTime;
  84. #endif
  85.  
  86.   DECLARE_STREAMABLE(_OWLCLASS, TFileDocument,1);
  87.   friend class _OWLCLASS_RTL TFileInStream;
  88.   friend class _OWLCLASS_RTL TFileOutStream;
  89. };
  90.  
  91. // Generic definitions/compiler options (eg. alignment) following the 
  92. // definition of classes
  93. #include <services/posclass.h>
  94.  
  95. #if defined(BI_NAMESPACE)
  96. } // namespace OWL
  97. #endif
  98.  
  99. //----------------------------------------------------------------------------
  100. // Inline implementations
  101. //
  102.  
  103. //
  104. inline TFileDocument::TFileDocument(TDocument* parent)
  105. :
  106.   TDocument(parent), FHdl(HFILE_ERROR), InfoPresent(false)
  107. {
  108. }
  109.  
  110. //
  111. inline TFileDocument::~TFileDocument()
  112. {
  113. }
  114.  
  115. //
  116. inline bool TFileDocument::IsOpen()
  117. {
  118.   return FHdl != HFILE_ERROR || TDocument::IsOpen();
  119. }
  120.  
  121. //
  122. // Return the number of property support by this document.
  123. // NOTE: The property count includes properties inherited from base document
  124. //       classes.
  125. //
  126. inline int TFileDocument::PropertyCount()
  127. {
  128.   return NextProperty - 1;
  129. }
  130.  
  131. #endif  // OWL_FILEDOC_H
  132.